package com.gxwz.document.business.service.impl;

import java.io.File;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gxwz.document.business.dao.IliteratureDao;
import com.gxwz.document.business.dao.impl.LiteratureDaoImpl;
import com.gxwz.document.business.entity.Literature;
import com.gxwz.document.business.entity.User;
import com.gxwz.document.business.service.IliteratureService;
import com.gxwz.document.core.pagination.Result;

@SuppressWarnings("unused")
@Service("litService")
public class LiteratureServiceImpl implements IliteratureService {
	
	@Resource(name = "literatureDao")
	private IliteratureDao litDao;

	@Override
	public void saveLit(Literature lit) {
		litDao.saveOrUpdate(lit);

	}
	/**
	 * 文献列表查询(分页)
	 */

	@Override
	public List<Literature> findByPage(int index, int pageSize){
		String hql = "from Literature";
		return litDao.findByPage(hql, index, pageSize);
	}

	@SuppressWarnings("unchecked")
	public List<Literature> findAll(){
		String hql ="from Literature";
		return litDao.find(hql);
	}
	@Override
	public void saveLiterature(Literature literature) {
		litDao.saveOrUpdate(literature);
	}
	@Override
	public int getRowNum() {
		
		return litDao.findAll().size();
	}
	@Override
	public Literature findById(int litId) {
		return litDao.findById(Literature.class, litId);
	}
	@Override
	public void update(Literature lit) {
		litDao.saveOrUpdate(lit);
		
	}
	@Override
	public void add(Literature lit) {
		
		litDao.saveOrUpdate(lit);
	}
	@Override
	public void delete(int litId) {
		litDao.delete(litDao.findById(Literature.class, litId));	
	}
	
	@Override
	public List<Literature> findByPageZero(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='零次文献' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageZeroDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='零次文献' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageOne(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='一次文献' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageOneDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='一次文献' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageTwo(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='二次文献' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageTwoDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='二次文献' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageThree(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='三次文献' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageThreeDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litGrade='三次文献' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageJournalArticle(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='期刊文章' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageJournalArticleDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='期刊文章' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageTreatise(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='专著'and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageTreatiseDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='专著'and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageProceedings(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='论文集' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageProceedingsDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='论文集' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageBachelorThesis(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='学士论文' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageBachelorThesisDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='学士论文' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageUndefined(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='未定义' and lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByPageUndefinedDel(int index, int pageSize) {
		String hql = "from Literature lit where lit.litTheme='未定义' and lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findByOder(Literature literature, int index, int pageSize) {
		return litDao.findbyOrder(literature, index, pageSize);
	}
	/**
	* 
	* @Description: 保存文件信息
	* @return
	 */
	@Override
	public void saveFileInfo(String uploadFileName, String savePath, String litType,String uploadContentType,String litGrade,String litTheme,Date  litUploadTime,double litSize) {
		/*Date date=new Date();   //获取当前系统时间
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   		String time = format.format(date); 
   		Timestamp Time = Timestamp.valueOf(time);//把String 类型转换成 Timestamp 类型
   		*/   
		Literature lit =new Literature();
   		lit.setUploadFileName(uploadFileName);
   		lit.setSavePath(savePath);
   		lit.setLitType(litType);
   		lit.setUploadContentType(uploadContentType);
   		lit.setLitGrade(litGrade);
   		lit.setLitTheme(litTheme);
   		lit.setLitUploadTime(litUploadTime);
   		lit.setLitSize(litSize);
   		litDao.saveOrUpdate(lit);
		
		
	}
	
	@Override
	public List<Literature> findDeletedo(int index, int pageSize) {
		String hql = "from Literature lit where lit.deleted='0'";
		return litDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<Literature> findDeleted(int index, int pageSize) {
		String hql = "from Literature lit where lit.deleted='1'";
		return litDao.findByPage(hql, index, pageSize);
	}
	
}
